package com.example.cpoopc.helloretrofit.bean;

import android.os.Parcel;
import android.os.Parcelable;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;

/**
 * UserInfo用户信息 数据结构
 * 
 * <br>Created 2014-8-21 下午3:05:52
 * @version  
 * @author   chenpeng		
 *
 * @see
 */
public class UserInfo implements Parcelable,Serializable{
    /**
     * 
     */
    private static final long serialVersionUID = -5875024896952887511L;
    public long uid; // 用户id
    public long fid;// 头像id
    public String nickname; // 昵称
    public int gender; // 性别：0保密 1男 2女
    public int grade; // 等级
    public String gname; // 加入团的团名
    public String prestige_title; // 头衔
    
    
    public UserInfo() {
        super();
    }


    public UserInfo(long uid, String nickname, int gender, int grade, String gname,
                    String prestigeTitle) {
        super();
        this.uid = uid;
        this.nickname = nickname;
        this.gender = gender;
        this.grade = grade;
        this.gname = gname;
        this.prestige_title = prestigeTitle;
    }
    
    public UserInfo(long uid, long fid, String nickname, int gender, int grade, String gname,
                    String prestigeTitle) {
        super();
        this.uid = uid;
        this.fid = fid;
        this.nickname = nickname;
        this.gender = gender;
        this.grade = grade;
        this.gname = gname;
        this.prestige_title = prestigeTitle;
    }

    
    private UserInfo(Parcel source){
        uid = source.readLong();
        fid = source.readLong();
        nickname = source.readString();
        gender = source.readInt();
        grade = source.readInt();
        gname = source.readString();
        prestige_title = source.readString();
        
    }
    public static final Creator<UserInfo> CREATOR = new Creator<UserInfo>() {

        @Override
        public UserInfo createFromParcel(Parcel source) {
            return new UserInfo(source);
        }

        @Override
        public UserInfo[] newArray(int size) {
            return new UserInfo[size];
        }
    };
    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeLong(uid);
        dest.writeLong(fid);
        dest.writeString(nickname);
        dest.writeInt(gender);
        dest.writeInt(grade);
        dest.writeString(gname);
        dest.writeString(prestige_title);
    }
    
    public JSONObject toJsonObject() throws JSONException{
        JSONObject user = new JSONObject();
        user.put("uid", uid);
        user.put("checkcode", fid);
        user.put("nickname", nickname);
        user.put("gender", gender);
        user.put("grade", grade);
        user.put("gname", gname);
        user.put("prestige_title", prestige_title);
        return user;
    }


	@Override
	public String toString() {
		return "UserInfo [uid=" + uid + ", nickname=" + nickname + "]";
	}
    
    
    
}
